<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>函数式组件使用props</title>

</head>
<body>
<div id="test"></div>
</body>
<script src="../js/react.development.js"></script>
<script src="../js/react-dom.development.js"></script>
<!--将jsx转为js-->
<script src="../js/babel.min.js"></script>
<!--babel  由babel转换jsx-->
<script src="../js/prop-types.js"></script>

<script type="text/babel">
    //1.创建类式组件
    function Person(props) {
        return (
            <ul>
                <li>姓名：{props.name}</li>
                <li>性别：{props.sex}</li>
                <li>年龄:{parseInt(props.age) + 1}</li>
            </ul>
        )
    }

    Person.propTypes = {
        name: PropTypes.string.isRequired,
        sex: PropTypes.string,
        age: PropTypes.number,
    }
    Person.defaultProps = {
        sex: '男',
        age: 18
    }

    //2.渲染组件到页面
    const p = {
        name: '张三',
    }
    ReactDOM.render(<Person {...p}/>, document.getElementById('test'))
</script>
</html>